package www.openteam.com.adapter.qualityCntrl;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.IPQCMsg00;
import www.openteam.com.bean.IPQCMsg01;

/**
 * Created by OT on 2018-01-09.
 */

public class IPQCAdapter00 extends RecyclerView.Adapter<IPQCAdapter00.ViewHolder> {

    Context context;
    List<IPQCMsg00.DataBeanX.DataBean> data00 = new ArrayList<>();
    OnLongClickListener onLongClickListener;

    public IPQCAdapter00(Context context) {
        this.context = context;
    }

    public void setOnLongClickListener(OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    public void setData00(List<IPQCMsg00.DataBeanX.DataBean> data00) {
        this.data00 = data00;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_ipqc_00, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        IPQCMsg00.DataBeanX.DataBean dataBean = data00.get(position);
        holder.ipqcItemProduceno.setText(dataBean.getProduceNo());
        holder.ipqcItemGroupname.setText(dataBean.getGroupname());
        holder.ipqcItemCustid.setText(dataBean.getCustid());
        holder.ipqcItemCustName.setText(dataBean.getCustName());
        holder.ipqcItemOrderno.setText(dataBean.getOrderno());
        holder.ipqcItemOnumb.setText(dataBean.getOnumb());
        holder.ipqcItemProdcode.setText(dataBean.getCode());
        holder.ipqcItemProdname.setText(dataBean.getName());
        holder.ipqcItemReqnumb.setText(dataBean.getReqnumb());
        holder.ipqcItemPartID.setText(dataBean.getPartID());
        holder.ipqcItemAproduce.setText(dataBean.getProcno());
        holder.ipqcItemAproducename.setText(dataBean.getProcname());
        holder.ipqcItemStype.setText(dataBean.getStype());
        holder.ipqcItemMorecom.setText(dataBean.getMorecom());
        holder.ipqcItemPID.setText(dataBean.getPID()+"");
        holder.ipqcItemZbid.setText(dataBean.getZbid()+"");
        
//        if (item.getStatusn().equals("已审核")) {
//            ischeckList.add(true);
        holder.linearLayout.setBackgroundColor(context.getResources().getColor(R.color.green));
//        } else  {
//            ischeckList.add(false);
//            viewHolder.cardView.setCardBackgroundColor(context.getResources().getColor(R.color.green));
//        }
        holder.linearLayout.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (onLongClickListener!=null){
                    onLongClickListener.onLongClick(position);
                }
                return false;
            }
        });
    }

    @Override
    public int getItemCount() {
        return data00.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.ipqc_item_Produceno)
        TextView ipqcItemProduceno;
        @Bind(R.id.ipqc_item_groupname)
        TextView ipqcItemGroupname;
        @Bind(R.id.ipqc_item_custid)
        TextView ipqcItemCustid;
        @Bind(R.id.ipqc_item_custName)
        TextView ipqcItemCustName;
        @Bind(R.id.ipqc_item_orderno)
        TextView ipqcItemOrderno;
        @Bind(R.id.ipqc_item_onumb)
        TextView ipqcItemOnumb;
        @Bind(R.id.ipqc_item_Prodcode)
        TextView ipqcItemProdcode;
        @Bind(R.id.ipqc_item_reqnumb)
        TextView ipqcItemReqnumb;
        @Bind(R.id.ipqc_item_Prodname)
        TextView ipqcItemProdname;
        @Bind(R.id.ipqc_item_PartID)
        TextView ipqcItemPartID;
        @Bind(R.id.ipqc_item_aproduce)
        TextView ipqcItemAproduce;
        @Bind(R.id.ipqc_item_aproducename)
        TextView ipqcItemAproducename;
        @Bind(R.id.ipqc_item_stype)
        TextView ipqcItemStype;
        @Bind(R.id.ipqc_item_morecom)
        TextView ipqcItemMorecom;
        @Bind(R.id.ipqc_item_PID)
        TextView ipqcItemPID;
        @Bind(R.id.ipqc_item_zbid)
        TextView ipqcItemZbid;
        @Bind(R.id.ipqc00_parent)
        LinearLayout linearLayout;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface OnLongClickListener{
        void onLongClick(int postion);
    }
}
